Object subclass: #BinTreeTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'BinTree'!

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

BinTreeTest class
	instanceVariableNames: ''!

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 16:39'!
printAllTraversals:theTree
	"print all traversals for a given tree"
	| traversal nextLabel |
	Transcript show: 'IN ORDER: '.
	RecursiveInorderTraversal print: theTree.
	Transcript cr.
	Transcript show: 'PRE ORDER: '.
	RecursivePreorderTraversal print: theTree.
	Transcript cr.
	Transcript show: 'POST ORDER: '.
	RecursivePostorderTraversal print: theTree.
	Transcript cr.
	Transcript show: 'IN ORDER FIRST/NEXT: '.
	traversal := InorderTraversal new: theTree.
	nextLabel := traversal first.
	[ nextLabel notNil ] whileTrue: [
		Transcript show: nextLabel.
		Transcript show: ' '.
		nextLabel := traversal next.
	].
	Transcript cr; cr.! !

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 16:40'!
test1
	"the first test for bintree"
	| node1 node2 node3 |
	Transcript show: '*** TEST 1 ***'; cr.
	node1 := BinTree new: 'A'.
	node2 := BinTree new: 'C'.
	node3 := BinTree new: 'B'.
	node1 addLeftKid: node2.
	node2 addRightKid: node3.
	BinTreeTest printAllTraversals: node1.! !

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 16:43'!
test2
	"test chain of left children"
	| n1 n2 n3 n4 n5 |
	Transcript show: '*** TEST 2 ***'; cr.
	n1 := BinTree new: 'A'.
	n2 := BinTree new: 'B'.
	n3 := BinTree new: 'C'.
	n4 := BinTree new: 'D'.
	n5 := BinTree new: 'E'.
	n1 addLeftKid: n2.
	n2 addLeftKid: n3.
	n3 addLeftKid: n4.
	n4 addLeftKid: n5.
	BinTreeTest printAllTraversals: n1.! !

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 17:03'!
test3
	"test chain of right children"
	| n1 n2 n3 n4 n5 |
	Transcript show: '*** TEST 3 ***'; cr.
	n1 := BinTree new: 'A'.
	n2 := BinTree new: 'B'.
	n3 := BinTree new: 'C'.
	n4 := BinTree new: 'D'.
	n5 := BinTree new: 'E'.
	n1 addRightKid: n2.
	n2 addRightKid: n3.
	n3 addRightKid: n4.
	n4 addRightKid: n5.
	BinTreeTest printAllTraversals: n1.! !

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 16:51'!
test4
	"single node"
	| node |
	Transcript show: '*** TEST 4 ***'; cr.
	node := BinTree new: 'A'.
	BinTreeTest printAllTraversals: node.! !

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 17:02'!
test5
	"big tree"
	| chelsea anya sara tammy tina hannah brenda kaila lisa felicia margaret |
	Transcript show: '*** TEST 5 ***'; cr.
	chelsea := BinTree new: 'CH'.
	anya := BinTree new: 'AN'.
	sara := BinTree new: 'SR'.
	tammy := BinTree new: 'TA'.
	tina := BinTree new: 'TE'.
	hannah := BinTree new: 'HN'.
	brenda := BinTree new: 'BR'.
	kaila := BinTree new: 'KA'.
	lisa := BinTree new: 'LI'.
	felicia := BinTree new: 'FC'.
	margaret := BinTree new: 'MC'.
	chelsea addLeftKid: anya.
	chelsea addRightKid: sara.
	sara addRightKid: tammy.
	tammy addRightKid: tina.
	sara addLeftKid: hannah.
	anya addRightKid: brenda.
	hannah addRightKid: kaila.
	kaila addRightKid: lisa.
	hannah addLeftKid: felicia.
	lisa addRightKid: margaret.
	BinTreeTest printAllTraversals: chelsea.! !

!BinTreeTest class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 17:03'!
testAll
	"run all tests"
	Transcript clear.
	BinTreeTest test1.
	BinTreeTest test2.
	BinTreeTest test3.
	BinTreeTest test4.
	BinTreeTest test5.! !
